package Test;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Author  zxy
 * Date  2023/1/5 上午 11:06
 */
public class Outer {

    public int age;

    public Outer(){

    }

    public Outer(int age) {
        this.age = age;
    }

    public void start() {
        Inner inner = new Inner();
        inner.cout();
    }

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Outer outer = new Outer(23);
        outer.start();

        Outer outer1 = new Outer(1);
        Outer.Inner inner = outer1.new Inner();
        inner.cout();

        /*Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        System.out.println(line);*/

        System.out.println(Color.RED);
        System.out.println(Enum.valueOf(Color.class, "RED"));
        System.out.println(Color.valueOf("YELLOW"));
        for(Color c : Color.values()) {
            System.out.println(c);
        }

        Class<Integer> integerClass = int.class;
        System.out.println(Modifier.toString(integerClass.getModifiers()));

        System.out.println(outer.getClass().getName());

        System.out.println("zzz: " + Outer.class.getResource("Student.class"));

        String className = "Test.Outer";
        Class cl = Class.forName(className);

        Field f = cl.getField("age");
        Object v = f.get(outer1);
        System.out.println("outer1: " + v);
        f.set(outer1, 1900);
        outer1.start();

        int[][] a = new int [2][];
        a[0] = new int[2];
        a[0][1] = 1;
        System.out.println(a[0][0]);


        Outer obj = (Outer) cl.getConstructor(int.class).newInstance(12);
        obj.start();

        Logger.getGlobal().setLevel(Level.INFO);
        Logger.getGlobal().info("基本日志");

        Logger myLogger = Logger.getLogger("com.myapp");
        myLogger.info("zxy");
        myLogger.warning("warn");
        myLogger.severe("severe");
        myLogger.throwing("Test.Outer", "main", new IOException());
        myLogger.log(Level.WARNING, "log", new IOException());
        System.out.println(myLogger.toString());

        int x;
        Scanner in = new Scanner(System.in);
        x = in.nextInt();
        assert x > 0;

    }

    // 内部类是一个编译器现象，与虚拟机无关
    public class Inner {

        public void cout() {
            String name = "zxy";
            System.out.println("age: " + age + "; name: " + name);
        }

    }

    public enum Color {
        RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLOW("黄色", 4);
        // 成员变量
        private String name;
        private int index;

        // 构造方法
        private Color(String name, int index) {
            this.name = name;
            this.index = index;
        }

        // 覆盖方法
        @Override
        public String toString() {
            return this.index + "_" + this.name;
        }
    }


}
